package com.xhs.annotation.controller;

import com.xhs.annotation.annotation.ApiUrl;
import com.xhs.annotation.request.UserRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import java.util.HashMap;

/**
 * @desc：
 * @author： xhs
 * @date： 2021/5/24 14:18
 * @version： JDK 1.8
 */
@Slf4j
@Validated
@RestController
public class UserController {

    /**
     * 获取用户接口
     *
     * @param userRequest
     * @return
     */
    @ApiUrl(name = "获取用户接口", url = "/user")
    @PostMapping("/user")
    public HashMap<String, Object> user(@RequestBody @Valid UserRequest userRequest) {
        HashMap<String, Object> map = new HashMap<>(16);
        map.put("code", 200);
        map.put("msg", "处理成功");
        map.put("data", userRequest);
        return map;
    }


    /**
     * @param name
     * @param pwd
     * @return
     */
    @ApiUrl(name = "获取用户接口2", url = "/getUser")
    @GetMapping("/getUser")
    public HashMap<String, Object> getUser(@NotEmpty(message = "用户名不能为空") String name,
                                           @NotEmpty(message = "密码不能为空") String pwd) {
        HashMap<String, Object> map = new HashMap<>(16);
        map.put("code", 200);
        map.put("msg", "处理成功");
        map.put("data", name);
        return map;
    }
}
